<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

$query = "SELECT admin FROM users WHERE user_id = " . $_SESSION[ 'user_id' ];
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if( isset( $row[ 'admin' ] ) && $row[ 'admin' ] == 1 ) {
?>
<html>
	<head>
		<title>Ages of Strife: Manage languages</title>
		<link type="text/css" rel="stylesheet" href="../global/agesofstrife.css" />
	</head>
	<body>
		<div id="root_container">
<?php
	include( "../global/ads.php" );
?>
			<div id="container">
<?php
	include_once( "../global/old_database_connection.php" );
?>
    			<div id="main-content">
<?php	
	if( isset( $_GET[ 'update_hashes' ] ) && $_GET[ 'update_hashes' ] == 'true' ) {
		translations_update_hashes();
		print( 'All translation hashes have been renewed.<br /><br />' );
	}
	if( isset( $_SESSION[ 'language_submit_status' ] ) ) {
		print( "<div class=\"blok\">" . $_SESSION[ 'language_submit_status' ] . "</div><br />\r\n" );
		unset( $_SESSION[ 'language_submit_status' ] );
	}

	$query = "SELECT translations_timestamp " .
			"FROM game " .
			"LIMIT 1";
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	$score = $row[ 'translations_timestamp' ];
	if( $row[ 'translations_timestamp' ] == -1 ) {
		$awardDate = 'Never';
	}
	else {
		$awardDate = date( 'd F Y', $row[ 'translations_timestamp' ] );
	}
?>
    				<div class="blok">
		    			<a href="admin.php">Back to the admin screen</a><br />
						<br />
						<strong>Award 1 premium turn to all approved translations</strong><br />
						Last awarded: <?php print( $awardDate ); ?><br />
						<form method="post" action="award_translators.php">
							<input type="checkbox" value="confirm_box" name="confirm_box" id="confirm-box" /> <label for="confirm-box"> Confirm</label><br /> 
							<input type="submit" value="confirm" /><br /> 
						</form>
						<br />
						<strong>Languages</strong><br />
						<ul>
<?php
	$query = "SELECT * " .
			"FROM languages " .
			"ORDER BY default_language DESC, language ASC";
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$num = mysql_numrows( $result );
	$i = 0;
	while ( $i < $num ) {
		if( mysql_result( $result, $i, "default_language" ) == 1 ) {
	    	$default = " - (default language)";
		}
		else {
			$default = "";
		}
		print( "<li>" . mysql_result( $result, $i, "title" ) . " (" . mysql_result( $result, $i, "language" ) . ") - <a href=\"languages.php?id=" . mysql_result( $result, $i, "language_id" ) . "\">Edit</a>" . "$default</li>" );
	    $i ++;
	}
	
	$language_id = -1;
	if( isset( $_GET[ 'id' ] ) && is_numeric( $_GET[ 'id' ] ) ) {
		$language_id = $_GET[ 'id' ];
	}
?>
						</ul>
						<br />
						<strong>Add new language</strong><br />
						<?php translations_print_language_form( 'submit_language.php', $language_id ); ?>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
	<?php
}
else {
	$_SESSION[ 'admin' ] = 0;
	header( "Location: ../overview/overview.php" );
}
?>